import { fromJS } from "immutable";
import * as actionTypes from "./constants";
import { getBannerRequest } from "../../../api/request";

export const changeBannerList = (data: any) => ({    
    type: actionTypes.CHANGE_BANNER,
    data: fromJS(data)
});

export const changeEnterLoading = (data: any) => ({
    type: actionTypes.CHANGE_ENTER_LOADING,
    data
});

export const getBannerList = () => {
    return (dispatch: any) => {
        getBannerRequest().then((bannerData: any) => {
            dispatch(changeBannerList(bannerData.banners));
            dispatch(changeEnterLoading(false)); // 改变 loading
        })
        .catch((error) => console.log("轮播图数据传输错误", error));
    };
};